package io.bio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class BioServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8080);
        System.out.println("服务器已启动，监听8080端口");
        while(true) {
            Socket request = serverSocket.accept();
            System.out.println("建立连接，" + request.toString());
            BufferedReader bufferedReader = null;
            try {
                bufferedReader = new BufferedReader(new InputStreamReader(request.getInputStream()));
                String str;
                while ((str = bufferedReader.readLine()) != null)
                    System.out.println("收到数据：" + str);
                System.out.println("数据接收完毕，数据来自：" + request.toString());
            } finally {
                bufferedReader.close();
            }
        }
    }
}
